<template>
  <div class="statistical">
    <Left-menus active="7"></Left-menus>
    <div class="statistical-main">
      <div class="head my-btn">
        <div class="search">
          <el-input placeholder="输入商品名称搜索" v-model="productName" clearable></el-input>
          <i class="el-icon-search" @click="search"></i>
        </div>
      </div>
      <div class="list">
        <h2>溯源统计</h2>
        <div class="content">
          <el-table :data="tableData" style="width:100%">
            <el-table-column prop="sourceCode" label="溯源码"></el-table-column>
            <el-table-column prop="productName" label="商品名称"></el-table-column>
            <el-table-column prop="batchId" label="溯源批次"></el-table-column>
            <el-table-column prop="scanNum" label="扫码统计"></el-table-column>
          </el-table>
          <el-pagination
            class="paging"
            align="right"
            @current-change="handleCurrentChange"
            :current-page.sync="curPage"
            hide-on-single-page
            :page-size="pageSize"
            layout="prev,pager,next,jumper"
            :total="count"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import LeftMenus from "@/views/components/TraceaLeftmenus";
export default {
  data() {
    return {
      curPage: 1,
      pageSize: 10,
      productName:'',
      count: null,
      tableData: [],
    };
  },
  created() {
    this.getTraceCodeStati()
  },
  methods: {
    async getTraceCodeStati() {
      let obj = {
        pageNum: this.curPage,
        pageSize:this.pageSize,
        productName: this.productName,
      };
      const res = await this.axios.getTraceCodeStati(obj);
      this.tableData = res.data.data.list
      this.tableData.map(el=>{
        el.sourceCode = el.sourceCode.substr(0,4)+"****"+el.sourceCode.substr(el.sourceCode.length-4,4)
      })
    },
    handleCurrentChange(val) {
      this.curPage = val
      this.getTraceCodeStati()
    },
    search(){
      this.curPage = 1
      this.getTraceCodeStati()
    }
  },
  components: {
    LeftMenus,
  },
};
</script>

<style lang="scss" scoped>
.statistical {
  display: flex;
  justify-content: center;
  .statistical-main {
    width: 960px;
    padding: 20px;
    padding-top: 0;
    .head {
      display: flex;
      justify-content: space-between;
      .search {
        cursor: pointer;
        display: flex;
        align-items: center;
        i {
          width: 34px;
          height: 34px;
          flex-shrink: 0;
          display: block;
          border-radius: 50%;
          background-color: #5bc6bb;
          line-height: 34px;
          text-align: center;
          color: #fff;
          margin-left: 10px;
        }
      }
      /deep/ .el-input__inner {
        width: 300px;
        height: 34px;
        background: rgba(255, 255, 255, 1);
        opacity: 1;
        border-radius: 17px;
      }
      /deep/ .el-input__inner:focus {
        border-color: #ddd;
      }
    }
    .list {
      margin-top: 15px;
      background-color: #fff;
      padding: 10px 15px;
      min-height: calc(100vh - 280px);
      h2 {
        padding-left: 15px;
        border-left: 4px solid #5bc6bb;
      }
      .content {
        margin-top: 25px;
        .paging {
          margin-top: 50px;
        }
      }
    }
  }
}
</style>